package com.bawei.module_main.ui

import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.CountDownTimer
import androidx.annotation.RequiresApi
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.library_common.BaseApplication
import com.bawei.library_common.route.ARouterActivityPath
import com.bawei.library_mvi.ui.BaseActivity
import com.bawei.module_main.R
import com.bawei.module_main.databinding.MainActivitySplashBinding

class SplashActivity : BaseActivity<MainActivitySplashBinding>(){
    private lateinit var countDownTimer:CountDownTimer
    override fun getLayout(): Int {
        return R.layout.main_activity_splash
    }

    @RequiresApi(Build.VERSION_CODES.P)
    override fun initView() {
        super.initView()
        //倒计时 5秒每隔1秒
        countDownTimer = object : CountDownTimer(5000,1000){
            override fun onTick(millisUntilFinished: Long) {
               viewDataBinding.tvSplashTime.text = String.format("倒计时%sS",millisUntilFinished/1000)
            }

            override fun onFinish() {
                //跳转到主页面
                ARouter.getInstance().build(ARouterActivityPath.PAGER_MAIN).navigation(this@SplashActivity)


               finish()
            }
        }
        countDownTimer.start()
        //获得app当前版本号
        val appVersionCode = BaseApplication.instance.getAppVersionCode()
        val appVersionName = BaseApplication.instance.getAppVersionName()

        viewDataBinding.tvSplashAppversion.text = String.format("当前版本号:%s,当前版本名称:%s",appVersionCode,appVersionName)
    }

    override fun onDestroy() {
        super.onDestroy()
        //取消倒计时
        countDownTimer.let {
            it.cancel()
        }
    }
}